#!/bin/bash

# OSCam daemon rc-script

daemon_name=oscam
daemon_args="-d 64 -b"

. /etc/rc.conf
. /etc/rc.d/functions

case "$1" in
  start)
    stat_busy "Starting OSCam daemon"
    sudo -u $daemon_name /usr/bin/$daemon_name $daemon_args
    # su --login -c "/usr/bin/$daemon_name $daemon_args" $daemon_name
      if [ $? -gt 0 ]; then
        stat_fail
        exit 1
      else
        add_daemon $daemon_name
        stat_done
      fi
  ;;

  stop)
    stat_busy "Stopping OSCam daemon"
    kill -9 `pidof /usr/bin/$daemon_name` &>/dev/null
    rm_daemon $daemon_name
    stat_done
  ;;

  restart)
    $0 stop
    sleep 3
    $0 start
  ;;
*)
  echo "usage: $0 {start|stop|restart}"
esac

exit 0
